import * as React from 'react';
import { Text, View } from 'react-native';
import { Link } from "../../util/react-router";
import { API } from "../../util/request";
import { NoticeBar } from '@ant-design/react-native';

class Home extends React.Component {
    state = {};

    constructor(props) {
        super(props);
        if (global.userInfo.ukey) {
            API.post("/weike/user/personalCenter", { '_ukey': global.userInfo.ukey }).then(_ => this.setState(_ => ({ isLogin: true }))).catch(_ => this.setState(_ => ({ isLogin: false }))).finally(() => !this.state.isLogin && this.goLogin());
        }
        else {
            this.goLogin();
        }
    }

    goLogin = () => {
        this.props.history.push({
            pathname: '/login',
            state: {}
        })
    }

    render() {
        return (<View>
            <Text style={[this.props.titleStyle]}>home</Text>
            <NoticeBar marqueeProps={{ loop: true }} mode="closable">
                Notice: 欢迎来到湖南汇富康达智能在线OA办公系统，这里的功能慢慢完善中...
            </NoticeBar>
            <Link to="/login">
                <Text>进入登录</Text>
            </Link>
        </View >);
    }
}

export { Home };